﻿using Apps.Common.ApiVersion;
using Microsoft.AspNetCore.Builder;
using Swashbuckle.AspNetCore.Swagger;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Apps.Extensions
{
    public static class MiddlewareHelper
    {
        /// <summary>
        /// Swagger授权中间件
        /// </summary>
        /// <param name="app"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseSwaggerExtentsion(this IApplicationBuilder app)
        {
            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                typeof(ApiVersion).GetEnumNames().ToList().ForEach(versoin =>
                {
                    options.SwaggerEndpoint($"/swagger/{versoin}/swagger.json", $"接口分类{versoin}");
                });
            });
            return app;
        }
    }
}
